-- serialize basic type
local fmt = {integer = "%d", float = "%a"}

function serialize (o)
	if type(o) == "number" then
		io.write(string.format(fmt[math.type(o)], o))
	elseif type(o) == "string" then
		io.write(string.format("%q", o))
	end
end

--[[
function serialize (o)
	local t = type(o)
	if t == "number" or t == "string" or
	   t == "boolean" or t == "nil" then
		 io.write(string.format("%q", o))
	end
end
--]]

-- serialize table
-- table without loop
function serialize1 (o)
	local t = type(o)
	if t == "number" or t == "string" or
		 t == "boolean" or t == "nil" then
		 io.write(string.format("%q", o))
	elseif t == "table" then
		io.write("{\n")
		for k, v in pairs(o) do
			io.write("  ", k, " = ")
			serialize1(v)
			io.write(",\n")
		end
		io.write("}\n")
	else
		error("cannot serialize a " .. type(o))
	end
end
-- table with loop
